import React, { Component } from 'react';

export default class RouterUtils extends React.Component
{
    static array = new Array();

    static pushRouter(pageName, pageKey)
    {
        var items = {'pageName': pageName, 'pageKey': pageKey};
        if (RouterUtils.isContainsPage(pageName))
        {
            RouterUtils.array[RouterUtils.findPos(pageName)].pageKey = pageKey;
        } else
        {
            RouterUtils.array.push(items);
        }
    }

    static popRouter(pageName, pageKey)
    {
        var items = {'pageName': pageName, 'pageKey': pageKey};
        var index = RouterUtils.array.indexOf(items);
        RouterUtils.array.splice(index, 1);
        console.log('RouterUtils.array.length:' + RouterUtils.array.length)
    }

    static findPos(pageName)
    {
        for (var i = 0; i < RouterUtils.array.length; i++)
        {
            if (RouterUtils.array[i].pageName == pageName)
            {
                return i;
            } else
            {
                continue;
            }
        }
    }

    static isContainsPage(pageName)
    {
        for (var i = 0; i < RouterUtils.array.length; i++)
        {
            if (RouterUtils.array[i].pageName == pageName)
            {
                return true;
            } else
            {
                continue;
            }
        }
        return false;
    }

    static getTapPageIndex()
    {
        for (var i = 0; i < RouterUtils.array.length; i++)
        {
            if (RouterUtils.array[i].pageName = 'Tab')
            {
                return RouterUtils.array[i + 1].pageKey;
            } else
            {
                continue;
            }
        }
    }

    static getFindPageIndex(pageName)
    {
        for (var i = 0; i < RouterUtils.array.length; i++)
        {
            if (RouterUtils.array[i].pageName = pageName)
            {
                return RouterUtils.array[i + 1].pageKey;
            } else
            {
                continue;
            }
        }
    }

}
